<?php declare(strict_types=1);

namespace App\Services\Store;

use App\Models\Company\CompanyConfig;
use App\Models\Store;

class StoreSignService
{

    public static function validateSign(string $store_id, string $company): array
    {
        try {
            $config = CompanyConfig::query()->where([
                "store_id" => $store_id,
                "company" => $company
            ])->first();
            if (!empty($config)) {
                $config = $config->toArray();
            }
            $isValidate = false;
            if (!empty($config) && $config["model"] == 4) {
                $isValidate = true;
            }
            if ($isValidate == false) {
                return [true, "无需验证"];
            }
            $store = Store::query()->select(["is_sign"])->where("store_id", $store_id)->first();
            if (empty($store)) {
                throw new \Exception("店铺不存在");
            }
            if ($store->is_sign != 2) {
                throw new \Exception("预充模式未成功签约");
            }
            return [true, "验证通过"];
        } catch (\Exception $e) {
            return [false, $e->getMessage()];
        }
    }

}